#include "opencv-4.h"

void OpenCV4::mat_create_demo()
{
	Mat m1, m2, m3;

	m1 = Mat::zeros(Size(256,256),CV_8UC3);
	m1 = Scalar(155,123,100);
	cout << m1 << endl;
	imshow("m1",m1);

	m1.copyTo(m2);
	m2 = Scalar(255,0,0);
	imshow("m2",m2);

	m3 = m1.clone();
	m3 = 0;
	imshow("m3",m3);
}

void OpenCV4::pix_visit_demo(Mat &image)
{
	int width = image.cols;
	int height = image.rows;
	int dims = image.channels();

	cout << "width:" << width << " height:" << height << " channles:" << dims << endl;

	for (int x = 0; x < height; x++)
	{
		for (int y  = 0; y < width; y++)
		{
			if (dims == 1)
			{
				int pv = image.at<uchar>(x, y);
				image.at<uchar>(x, y) = 255 - pv;
			}
			if (dims == 3)
			{
				Vec3b pv = image.at<Vec3b>(x, y);
				image.at<Vec3b>(x, y)[0] = 255 - pv[0];
				image.at<Vec3b>(x, y)[1] = 255 - pv[1];
				image.at<Vec3b>(x, y)[2] = 255 - pv[2];
			}		
		}
	}

	imshow("visit picture",image);
}


